#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstring>

const int N = 300005;
int n, m, num, res, maxlen;
int e_cnt, heads[N], sum[N], dep[N], dis[N], w[N], f[21][N];

inline int read() {
  int res = 0, ch = getchar();
  bool flag = false;
  while (!isdigit(ch)) {
    if (ch == '-') flag = true;
    ch = getchar();
  }
  while (isdigit(ch)) res = (res << 1) + (res << 3) + (ch ^ 48), ch = getchar();
  return flag ? -res : res;
}

struct Edge {
  int v, nxt, w;
} e[N << 1];

struct Query {
  int s, t, lca, len;
} Q[N];

inline void add(int u, int v, int w) {
  e[++e_cnt].v = v, e[e_cnt].nxt = heads[u], heads[u] = e_cnt, e[e_cnt].w = w;
}

void solve(int x) {
  for (int i = heads[x], v; i; i = e[i].nxt) {
    if ((v = e[i].v) != f[0][x]) {
      solve(v);
      sum[x] += sum[v];
    }
  }
  if (sum[x] == num && res < w[x]) {
    res = w[x];
  }
}

inline bool check(int mid) {
  memset(sum, 0, sizeof(sum));
  res = num = 0;
  for (int i = 1; i <= m; ++i) {
    if (Q[i].len > mid) {
      ++sum[Q[i].s], ++sum[Q[i].t];
      sum[Q[i].lca] -= 2;
      ++num;
    }
  }
  solve(1);
  return maxlen - res <= mid;
}

void dfs(int x) {
  for (int i = heads[x], v; i; i = e[i].nxt)
    if ((v = e[i].v) != f[0][x]) {
      dep[v] = dep[x] + 1, f[0][v] = x;
      w[v] = e[i].w;
      dis[v] = dis[x] + e[i].w;
      dfs(v);
    }
}

inline int LCA(int x, int y) {
  if (dep[x] < dep[y]) std::swap(x, y);
  for (int i = 20; ~i; --i) {
    if (dep[f[i][x]] >= dep[y]) x = f[i][x];
  }
  if (x == y) return x;
  for (int i = 20; ~i; --i) {
    if (f[i][x] != f[i][y]) x = f[i][x], y = f[i][y];
  }
  return f[0][x];
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#endif
#ifndef LOCAL
  freopen("CppTest.in", "r", stdin);
  freopen("CppTest.out", "w", stdout);
#endif
#endif

  n = read(), m = read();
  for (int i = 1, a, b, t; i < n; ++i) {
    a = read(), b = read(), t = read();
    add(a, b, t);
    add(b, a, t);
  }
  for (int i = 1; i <= m; ++i) {
    Q[i].s = read(), Q[i].t = read();
  }
  dfs(1);
  for (int i = 1; i < 21; ++i) {
    for (int j = 1; j <= n; ++j) {
      f[i][j] = f[i - 1][f[i - 1][j]];
    }
  }
  for (int i = 1; i <= m; ++i) {
    Q[i].lca = LCA(Q[i].s, Q[i].t);
    Q[i].len = dis[Q[i].s] + dis[Q[i].t] - (dis[Q[i].lca] << 1);
    maxlen = std::max(maxlen, Q[i].len);
  }
  int l = 0, r = maxlen, mid, ans;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (check(mid)) {
      r = mid - 1, ans = mid;
    } else {
      l = mid + 1;
    }
  }
  printf("%d", ans);
  return 0;
}